/* $Id:field.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __FIELD_H
#define __FIELD_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "value.h"

#define loopFieldValue(r,v) loopSingle((r)->listValue(),v,class value,list)

class field {
    int nr;
    string name;
    int type;
    class record *related;
    map<string,class value> value;
    int maxValue;
    string description;
    string abbreviation;
public:
    field();

    // Field : nr
    const int getNr() const;
    void setNr(const int v);
    int operator<(const field &ck) const;

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : type
    enum type_enum{type_number,type_float,type_enumerate,type_position,type_string,type_relation,type_parent,type_children,type_boolean};
    const int getType() const;
    const string showType() const;
    void setType(const int v);
    void setType(const string v);

    // Field : related
    class record& getRelated() const;
    void setRelated(class record &v);

    // Field : value
    class value& getValue(const string v);
    list<class value>& listValue();
    void setValue(class value &v);
    void delValue(const string v);
    const bool isValue(const string v) const;

    // Field : description
    const string getDescription() const;
    void setDescription(const string v);

    // Field : abbreviation
    const string getAbbreviation() const;
    void setAbbreviation(const string v);

    void xml(ofstream &f, int l=0, int r=0);
};

#endif // __FIELD_H
